<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:a="http://www.w3.org/2005/Atom"
        xmlns:exslt="http://exslt.org/common"
		xmlns:func="http://exslt.org/functions"
		xmlns:str="http://exslt.org/strings"
		xmlns:dyn="http://exslt.org/dynamic"
		xmlns:ib="http://ionrock.org/ionblog/xslt/func"
		xmlns:xh="http://www.w3.org/1999/xhtml"
		xmlns:f="http://xmlns.4suite.org/ext"
		xmlns:bc="http://brightcontent.net/ns/"
        xmlns:xf="http://www.w3.org/2002/xforms"
        xmlns:thr="http://purl.org/syndication/thread/1.0"
		xmlns="http://www.w3.org/1999/xhtml"
		extension-element-prefixes="func str dyn ib exslt" 
		exclude-result-prefixes="a xsl dyn str xh #default">

  <xsl:import href="../common/util.xslt"/>
  <xsl:param name="param-title">My Web Log</xsl:param>
  <xsl:param name="param-collection">ionrock</xsl:param>
  <xsl:param name="bc:weblog-base-uri"/>
  <xsl:param name="bc:template_files"/>
  <xsl:param name="bc:brightcontent.archives.parse"/>
  <xsl:param name="bc:brightcontent.archives.history"/>
  <xsl:param name="bc:brightcontent.calendar"/>
  <xsl:param name="bc:brightcontent.calendar.parse"/>
  <xsl:param name="bc:brightcontent.comments" />
  <xsl:param name="bc:brightcontent.comments.for-current-entry" />
  <xsl:param name="bc:brightcontent.comments.parse" />
  <!--
  <xsl:param name="bc:brightcontent.comments.forms" />
  <xsl:param name="bc:brightcontent.comments.forms.parse" />
  -->
  <xsl:param name="bc:brightcontent.delicious.feed"/>
  <xsl:param name="bc:brightcontent.delicious.feed.parse"/>
  <xsl:param name="bc:ionrock.about" />
  <xsl:param name="bc:ionrock.links" />
  <xsl:output method="html" indent="yes" />

  <xsl:variable name="tplbase" select="'ionrock/htdocs'"/>

  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="a:feed">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xh="http://www.w3.org/1999/xhtml">
  <head>
    <title><xsl:value-of select="./a:title" /></title>
    <meta name="generator" content="Bright Content" />
    <link rel="stylesheet" href="{$bc:template_files}/{$tplbase}/css/style.css" type="text/css" />
  </head>
  <body>
    <div id="main-container">
      <div id="page">
	<div id="main-header">
	  <h1>Ionrock Dot Org</h1>
	</div>
	<div id="sidebar">
	<xsl:if test="$bc:brightcontent.calendar.parse">
  	  <h3>Calendar</h3>
        <xsl:copy-of select="dyn:evaluate($bc:brightcontent.calendar.parse)"/>
	</xsl:if>
	<xsl:if test="$bc:brightcontent.archives.parse">
  	  <h3>Archives</h3>
  	  <ul>
        <xsl:for-each select="dyn:evaluate($bc:brightcontent.archives.parse)/*/link">
          <li>
            <a href="{@href}"><xsl:value-of select="@title"/></a>
    	    </li>
    	  </xsl:for-each>
  	  </ul>
	</xsl:if>
          <xsl:if test="$bc:brightcontent.delicious.feed">
           <h3>Del.icio.us</h3>
           <div class="delicious-links">
            <xsl:copy-of select="dyn:evaluate($bc:brightcontent.delicious.feed.parse)"/>
           </div>
          </xsl:if>
          <xsl:if test="$bc:ionrock.links">
           <xsl:comment>from <xsl:value-of select="$bc:ionrock.links" /></xsl:comment>
           <xsl:copy-of select="document($bc:ionrock.links)" />
          </xsl:if>
          <xsl:if test="$bc:ionrock.about">
           <xsl:comment>from <xsl:value-of select="$bc:ionrock.about" /></xsl:comment>
           <xsl:copy-of select="document($bc:ionrock.about)" />
          </xsl:if>
	</div>
	<div id="main-content">
	  <xsl:variable name="root-node" select="." />
	  <h3><xsl:value-of select="$param-title" /></h3>
          <xsl:variable name="entry-count" select="count(a:entry)" />
          <xsl:choose>
           <xsl:when test="$entry-count = 1">
            <xsl:apply-templates select="a:entry">
             <xsl:with-param name="do-comments" select="true()" />
            </xsl:apply-templates>
           </xsl:when>
           <xsl:otherwise>
            <xsl:apply-templates select="a:entry" />
           </xsl:otherwise>
          </xsl:choose>
	</div>
      </div>
    </div>
  </body>
</html>
  </xsl:template>
  
  <func:function name="ib:blog-id">
    <xsl:param name="old-id" />
    <xsl:variable name="old-base">http://ionrock.org/atom</xsl:variable>
    <xsl:variable name="new-base">/blogs/view</xsl:variable>
    <func:result select="str:replace($old-id, $old-base, $new-base)" />
  </func:function>

  <xsl:template match="a:feed/a:author | a:feed/a:title">
   <!-- this is not used in the template -->
  </xsl:template>
  
  <xsl:template match="a:entry">
   <xsl:param name="do-comments" select="false()" />
   <div class="blog-entry">
    <h4><xsl:value-of select="a:title" /></h4>
    <div class="blog-content">
     <xsl:apply-templates select="a:content" />
    </div>
    <div class="blog-details">
     <span class="blog-posted">Posted: <xsl:value-of select="a:published" /></span>
     <xsl:if test="string(a:published) != string(a:updated)">
      <span class="blog-updated">Updated: <xsl:value-of select="a:updated" /></span>
     </xsl:if>
     <xsl:if test="a:author/a:name">
      By <xsl:apply-templates select="a:author" mode="text-construct" />
     </xsl:if>
     <div class="blog-links">
      <xsl:apply-templates select="a:link" mode="links" />
     </div>
    </div>
   </div>

   <xsl:if test="$do-comments">
    <xsl:variable name="comments-feed" select="a:link[@rel='replies']/@href" />
    <!--xsl:if test="$bc:brightcontent.comments.for-current-entry"-->
    <xsl:message><xsl:value-of select="$comments-feed"/></xsl:message>
    <xsl:if test="$comments-feed">
      <div id="comment-thread">
       <!--xsl:apply-templates select="document(concat($comments-feed, '?entryid=', a:id))" mode="comments"/-->
       <xsl:apply-templates select="document($comments-feed)" mode="comments"/>
      </div>
    </xsl:if>
    <!--xsl:message><xsl:copy-of select="$bc:brightcontent.comments"/></xsl:message-->
    <xsl:if test="$bc:brightcontent.comments = 'enabled'">
     <a name="comments" />
     <div id="comment-area">
      <!--xsl:copy-of select="dyn:evaluate($bc:brightcontent.comments.forms.parse)" /-->
      <xsl:call-template name="comment-form">
        <xsl:with-param name="action" select="a:link[@rel='alternate']/@href" />
      </xsl:call-template>
     </div>
    </xsl:if>
   </xsl:if>
  </xsl:template>

  <xsl:template match="*" mode="comments" />
  
  <xsl:template match="a:feed" mode="comments">
   <xsl:variable name="comment-feed-link" select="./a:link[@rel = 'self']" />
   <xsl:choose>
    <xsl:when test="$comment-feed-link">
     <h4><a href="{$comment-feed-link/@href}"><xsl:value-of select="/a:feed/a:title" /></a></h4>
    </xsl:when>
    <xsl:otherwise>
     <h4><xsl:value-of select="/a:feed/a:title" /></h4>
    </xsl:otherwise>
   </xsl:choose>
   <xsl:apply-templates select="./a:entry" mode="comments" />
  </xsl:template>

  <xsl:template match="a:entry" mode="comments">
   <xsl:variable name="author" select="./a:author" />
   <div class="comment-entry">
    <div class="comment-content">
     <xsl:copy-of select="./a:content/node()" />
    </div>
    <xsl:choose>
     <xsl:when test="$author/a:uri">
      <span class="comment-details">Posted by <a href="{$author/a:uri}"><xsl:value-of select="$author/a:name" /></a></span>
     </xsl:when>
     <xsl:otherwise>
      <span class="comment-details">Posted by <xsl:value-of select="$author/a:name" /></span>
     </xsl:otherwise>
    </xsl:choose>
   </div>
  </xsl:template>

  <xsl:template match="thr:in-reply-to" mode="comments">
   <!-- pass -->
  </xsl:template>

  <xsl:template match="a:author" mode="text-construct">
    <xsl:value-of select="a:name" />
  </xsl:template>

  <!-- overrides for util.xslt -->
  <xsl:template match="a:link" mode="links">
    <xsl:variable name="href">
      <xsl:choose>
        <xsl:when test="starts-with(@href, 'http')">
          <xsl:value-of select="@href" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="f:resolve-url($bc:weblog-base-uri, @href)" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    
    <a href="{$href}">
      <xsl:if test="not(@rel)">[generic link]</xsl:if>
      <xsl:value-of select="@title"/>
    </a>
    <xsl:if test="position() != last()">
      <xsl:text> | </xsl:text>
    </xsl:if>
  </xsl:template>
  
</xsl:stylesheet>